from PyQt5.QtCore import Qt, pyqtSignal, pyqtSlot
from PyQt5.QtWidgets import QMessageBox


class RemoveDialog(QMessageBox):
    removed = pyqtSignal(str, str)

    def __init__(self, parent, model, field):
        super().__init__(parent)
        
        tablename = model.tableName()
        if(tablename=='DataTypes'):
            self.typename = tablename
        else:
            self.typename = " ".join(tablename.split()[1:])

        self.field = field

        self.setText('Warning: If you delete {0} "{1}", all data of that type will also be permanently deleted.'.format(self.typename, self.field))
        self.setInformativeText('Are you sure you wish to continue?')
        self.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
        self.setDefaultButton(QMessageBox.No)
        self.setIcon(QMessageBox.Warning)
        self.accepted.connect(self.onYes)
        self.rejected.connect(self.onNo)
        


    @pyqtSlot()
    def onYes(self):
        self.removed.emit(self.typename, self.field)
        self.close()


    @pyqtSlot()
    def onNo(self):
        self.close()
